/*
 * @(#)ForgotPasswordBOImpl.java 1.0 2012/03/06
 *
 * Copyright (c) 
 *
 * 
 */

package mock.ab_sd.business;

import java.util.ArrayList;
import mock.ab_sd.common.valueobject.UserVO;
import mock.ab_sd.daointerface.UserDAOImpl;

/**
 * ForgotPasswordBOImpl class 
 * @author QuyGP
 * @created 15/8/2012
 */
public class ForgotPasswordBOImpl implements ForgotPasswordBO{
	
	/**
	 * authenticate whether user name and email match database,
	 *     if match then return password, otherwise return empty string
	 * @param userName
	 * @param email
	 * @return a string is password or an empty string    
	 * @throws Exception
	 * @author QuyGP
	 * @created 15/8/2012
	 */
	public String authenticate(String userName, String email) throws Exception {
		
		// declare variable to store password that is returned from database
		String result = "";
		
		// create an UserDAOImpl object
		UserDAOImpl userDAO = new UserDAOImpl();
		
		/* declare an ArrayList of UserVO to get an ArrayList that is returned
		 * from getArrayListOfUser method 		
		 */
		ArrayList<UserVO> arrayListOfUser = userDAO.getArrayListOfUser();
		
		// to step through the elements in arrayList
		for (UserVO user : arrayListOfUser) {
			
			/* if user name and password match database,
			 * then assign password of the user to result
			 */
			if (userName.equals(user.getUserName())
					&& email.equals(user.getEmail())) {
				result = user.getPassword();
			}
		}
		return result; // return password or an empty string
	}
}
